home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / More Files / form-to-email_user.php < prev    next >
PHP Script  |  2013-07-17  |  2KB  |  83 lines

  1. <?php
  2.  
  3. if(!isset($_POST['submit']))
  4. {
  5.     //This page should not be accessed directly. Need to submit the form.
  6.     echo "error; you need to submit the form!";
  7. }
  8.  
  9. $copy_email = $_POST['CopyEmail'];
  10. $school = $_POST['School'];
  11. $reason = $_POST['Reason'];
  12. $person = $_POST['Person'];
  13. $class = $_POST['Class'];
  14. $wveis = $_POST['WVEIS'];
  15. $newpassword = $_POST['Newpassword'];
  16. $contact = $_POST['Contact'];
  17. $date = date("F j, Y, g:i a");
  18.  
  19. //Validate first
  20. if(empty($contact)||empty($copy_email)) 
  21. {
  22.     echo "Name and email are mandatory!";
  23.     exit;
  24. }
  25.  
  26. if(IsInjected($copy_email))
  27. {
  28.     echo "Bad email value!";
  29.     exit;
  30. }
  31.  
  32. $email_subject = "Username requested - $school";
  33. $email_body = "The following user request was entered on $date \r\n
  34.     SCHOOL: $school 
  35.     REASON: $reason 
  36.     NAME: $person 
  37.     GRADE: $class 
  38.     WVEIS NO: $wveis 
  39.     NEW PASSWORD: $newpassword
  40.     CONTACT: $contact\r\n";
  41.     
  42. $email_to = "psines@access.k12.wv.us,brrmarti@access.k12.wv.us";
  43. $headers = "From: $copy_email\r\n";
  44. $headers .= "CC: $copy_email\r\n";
  45.  
  46.  
  47. //Send the email!
  48. if (mail($email_to,$email_subject,$email_body,$headers)){
  49.  
  50.  
  51. //done. redirect to thank-you page.
  52. header('Location: thank-youuser.html');
  53. }
  54. else{
  55. header('Location: problem.html');
  56. }
  57.  
  58.  
  59. // Function to validate against any email injection attempts
  60. function IsInjected($str)
  61. {
  62.   $injections = array('(\n+)',
  63.               '(\r+)',
  64.               '(\t+)',
  65.               '(%0A+)',
  66.               '(%0D+)',
  67.               '(%08+)',
  68.               '(%09+)'
  69.               );
  70.   $inject = join('|', $injections);
  71.   $inject = "/$inject/i";
  72.   if(preg_match($inject,$str))
  73.     {
  74.     return true;
  75.   }
  76.   else
  77.     {
  78.     return false;
  79.   }
  80. }
  81.  
  82.  
  83. ?>